package de.hwrberlin.remo.diagram.properties.internal;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

public class RemoDiagramPropertiesPlugin extends AbstractUIPlugin {

	// The plug-in ID
	public static final String PLUGIN_ID = "de.hwrberlin.remo.diagram.properties"; //$NON-NLS-1$

	// The shared instance
	private static RemoDiagramPropertiesPlugin plugin;
	
	/**
	 * The constructor
	 */
	public RemoDiagramPropertiesPlugin() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		
		ImageRegistry registry = getImageRegistry();
		registry.put(Images.UP_IMAGE, getImageDescriptor(Images.UP_IMAGE));
		registry.put(Images.DOWN_IMAGE, getImageDescriptor(Images.DOWN_IMAGE));
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static RemoDiagramPropertiesPlugin getDefault() {
		return plugin;
	}
	
	public static Image getImage(String key) {
		if(plugin != null) {
			ImageRegistry registry = plugin.getImageRegistry();
			return registry.get(key);
		}
		
		return null;
	}
	
	private static ImageDescriptor getImageDescriptor(String path) {
		return imageDescriptorFromPlugin(PLUGIN_ID, path);
	}
}